package com.wcl.demo.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wcl.demo.R;

import java.util.List;

/**
 * Created by dllo on 15/12/3.
 */
public class BlackListAdapter extends BaseAdapter {
    private List<String> datas;

    public void addData(List<String> datas){
        this.datas=datas;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return datas!=null&&datas.size()>0?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas!=null&&datas.size()>0?datas.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(datas!=null&&datas.size()>0){
            ViewHolder holder;
            if(convertView==null){
                holder=new ViewHolder();
                convertView= LayoutInflater.from(parent.getContext()).inflate(R.layout.blacklist_item,null);
                holder.blacklist_item_image= (ImageView) convertView.findViewById(R.id.blacklist_item_image);
                holder.blacklist_item_text= (TextView) convertView.findViewById(R.id.blacklist_item_text);
                convertView.setTag(holder);
            }else{
                holder= (ViewHolder) convertView.getTag();
            }
            holder.blacklist_item_text.setText(datas.get(position));
        }
        return convertView;
    }
    class ViewHolder{
        private ImageView blacklist_item_image;
        private TextView blacklist_item_text;
    }
}
